﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LinqDataSource.aspx.cs" Inherits="WebTestharness.Service.LinqDataSource" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Insert/Update/Delete Using LinqDataSource</title>
    <style  type="text/css">
        .label
        {
            text-align:right;
            width:100px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FormView ID="FormView1" runat="server" CellPadding="4" 
         DefaultMode="Insert" DataKeyNames="CustomerID"
            DataSourceID="customersource" ForeColor="#333333" 
            oniteminserted="FormView1_ItemInserted">
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#EFF3FB" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <InsertItemTemplate>
                <table>
                    <tr>
                        <td class="label">CustomerID:</td>
                        <td>
                            <asp:TextBox ID="TextBox1" runat="server" 
                            Text='<%# Bind("CustomerID") %>' />
                        </td>
                    </tr>
                    <tr>
                        <td class="label">CompanyName:</td>
                        <td>
                            <asp:TextBox ID="CompanyNameTextBox" runat="server" 
                            Text='<%# Bind("CompanyName") %>' />
                        </td>
                    </tr>
                    <tr>
                        <td class="label">ContactName:</td>
                        <td>
                            <asp:TextBox ID="ContactNameTextBox" runat="server" 
                            Text='<%# Bind("ContactName") %>' />
                        </td>
                    </tr>
                    <tr>
                        <td class="label">ContactTitle:</td>
                        <td>
                            <asp:TextBox ID="ContactTitleTextBox" runat="server" 
                            Text='<%# Bind("ContactTitle") %>' />
                        </td>
                    </tr>
                    <tr>
                        <td class="label">Phone:</td>
                        <td>
                           <asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>' /> 
                        </td>
                    </tr>
                    <tr>
                        <td  style="text-align:center"  colspan="2">
                            <asp:Button ID="insert" runat="server" CommandName="Insert"
                             Text="Insert" />
                        </td>
                    </tr>
                </table>
            </InsertItemTemplate>
        </asp:FormView>
        <br />
    <asp:GridView ID="customergrid" runat="server"
     AllowPaging="True"
     DataSourceID="customersource"
     DataKeyNames="CustomerID"
      AutoGenerateColumns="False" 
      AutoGenerateSelectButton="true"
       AutoGenerateEditButton="True"
        AutoGenerateDeleteButton="True" AllowSorting="True" CellPadding="4" 
            ForeColor="#333333" GridLines="None"
     >
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#EFF3FB" />
     <Columns>
        <asp:BoundField DataField="CompanyName" HeaderText="Company" 
             SortExpression="CompanyName" />
        <asp:BoundField DataField="ContactName" HeaderText="Name" 
             SortExpression="ContactName" />
        <asp:BoundField DataField="ContactTitle" HeaderText="Title" 
             SortExpression="ContactTitle" />
             <asp:BoundField DataField="Phone" HeaderText="Phone" 
             SortExpression="Phone" />
     </Columns>
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <AlternatingRowStyle BackColor="White" />
     </asp:GridView>
    <asp:LinqDataSource id="customersource" runat="server"
     ContextTypeName="NorthWindDataContext"
      TableName="Customers"
      OrderBy="ContactName"
      EnableInsert="true"
      EnableUpdate="true"
      EnableDelete="true"
       AutoSort="true"
       AutoPage="true" />
       
       <br />
       
        <asp:DetailsView ID="DetailsView1" runat="server"
          DataSourceID="singlecustomer" DefaultMode="ReadOnly" />
        
       <asp:LinqDataSource id="singlecustomer" runat="server"
     ContextTypeName="NorthWindDataContext"
      TableName="Customers"
       Where="CustomerID=@customerid"
      >
        <WhereParameters>
            <asp:ControlParameter Name="customerid"  ControlID="customergrid"  />
        </WhereParameters>
      </asp:LinqDataSource>
     
    </div>
    </form>
</body>
</html>